#ifndef LANGUAGERECOGNIZER_H
#define LANGUAGERECOGNIZER_H

#include "define.h"
#include "setting.h"

#include <QNetworkAccessManager>

class LanguageRecognizer : public QNetworkAccessManager {
    Q_OBJECT

public:
    struct RequestContent {
        QString address = ADDRESS_RECOGNIZE;
        QString textToRecognize;
        QString appid = SETTING.getAppId();
        QString salt;
        QString sign;
        QString pwd = SETTING.getSecretKey();
    };

public:
    LanguageRecognizer(QObject* parent);

    void recognize(const QString& text);

signals:
    void languageRecgnized(const QString& text, Language language);

private:
    void onReply(QNetworkReply* reply);
    Language languageInReply(QNetworkReply* reply);

    QString stringToSignFromContent(const RequestContent& content);

private:
    RequestContent m_content;
};

#endif // LANGUAGERECOGNIZER_H
